package GUI.pdaGrafica;

import javax.swing.JPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JWindow;
import javax.swing.BorderFactory;

import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.Color;
import javax.swing.border.EtchedBorder;
import javax.swing.JButton;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;

import modelo.Restaurante;

import java.awt.Point;
import java.awt.Dimension;
import java.awt.ComponentOrientation;


/**
 * Esta clase implementa el menú principal de la aplicación que correrá en las PDA.
 * Mantiene un atributo de tipo Restaurante
 * 
 * @created 03-may-2007 19:39
 * @version 1.0
 * @author Enrique Menor Santos
 *
 */
public class MenuPrincipal extends JWindow implements ActionListener {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JButton jBComandas = null;

	private JButton jBPlatos = null;

	private JButton jBSalir = null;
	/**
	 * Objeto restaurante a gestionar. Se pasará como parámetro al resto de clases visuales. 
	 */
	private Restaurante r;

	
	/**
	 * Constructor público
	 * 
	 */
	public MenuPrincipal(Restaurante r) {
		this.r=r;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(240, 320);
		this.setPreferredSize(new Dimension(240, 320));
		this.setName("menuPrincipal");
		this.setMaximumSize(new Dimension(240, 320));
		this.setMinimumSize(new Dimension(240, 320));
		this.setLocation(new Point(0, 0));
		this.setVisible(false);
		this.setContentPane(getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "MENÚ PRINCIPAL", TitledBorder.CENTER, TitledBorder.ABOVE_TOP, new Font("Lucida Sans", Font.BOLD, 14), Color.black));
			jContentPane.setToolTipText("Elija una opción del Menú Principal");
			jContentPane.setName("panelPrincipal");
			jContentPane.setComponentOrientation(ComponentOrientation.UNKNOWN);
			jContentPane.add(getJBComandas(), null);
			jContentPane.add(getJBPlatos(), null);
			jContentPane.add(getJBSalir(), null);
			jContentPane.add(Box.createVerticalGlue());
			jContentPane.add(Box.createVerticalGlue());
			jContentPane.add(Box.createVerticalGlue());
			jContentPane.add(Box.createVerticalGlue());
		}
		return jContentPane;
	}
	/**
	 * This method initializes jBComandas	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJBComandas() {
		if (jBComandas == null) {
			jBComandas = new JButton();
			jBComandas.setActionCommand("comandas");
			jBComandas.setIcon(new ImageIcon(getClass().getResource("/iconos/table_edit.png")));
			jBComandas.setText("PEDIDOS ...");
			jBComandas.setName("comandas");
			jBComandas.setPressedIcon(new ImageIcon(getClass().getResource("/iconos/table_go.png")));
			jBComandas.setDisabledIcon(new ImageIcon(getClass().getResource("/iconos/table_delete.png")));
			jBComandas.setToolTipText("Click para acceder a pedidos");
			jBComandas.setLocation(new Point(44, 45));
			jBComandas.setSize(new Dimension(150, 75));
			jBComandas.setMnemonic(KeyEvent.VK_C);
			jBComandas.addActionListener(this);
		}
		return jBComandas;
	}

	/**
	 * This method initializes jBPlatos	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJBPlatos() {
		if (jBPlatos == null) {
			jBPlatos = new JButton();
			jBPlatos.setActionCommand("platos");
			jBPlatos.setIcon(new ImageIcon(getClass().getResource("/iconos/cup.png")));
			jBPlatos.setMnemonic(KeyEvent.VK_P);
			jBPlatos.setName("platos");
			jBPlatos.setPressedIcon(new ImageIcon(getClass().getResource("/iconos/cup_go.png")));
			jBPlatos.setText("SERVIR PLATOS");
			jBPlatos.setToolTipText("Click para ver patos listos");
			jBPlatos.setPreferredSize(new Dimension(136, 26));
			jBPlatos.setLocation(new Point(45, 136));
			jBPlatos.setSize(new Dimension(150, 75));
			jBPlatos.setDisabledIcon(new ImageIcon(getClass().getResource("/iconos/cup_delete.png")));
			jBPlatos.addActionListener(this);
		}
		return jBPlatos;
	}

	/**
	 * This method initializes jBSalir	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJBSalir() {
		if (jBSalir == null) {
			jBSalir = new JButton();
			jBSalir.setActionCommand("salir");
			jBSalir.setMnemonic(KeyEvent.VK_S);
			jBSalir.setName("salir");
			jBSalir.setPressedIcon(new ImageIcon(getClass().getResource("/iconos/door.png")));
			jBSalir.setText("SALIR");
			jBSalir.setToolTipText("Click para salir de la aplicación");
			jBSalir.setPreferredSize(new Dimension(136, 26));
			jBSalir.setLocation(new Point(44, 225));
			jBSalir.setSize(new Dimension(150, 75));
			jBSalir.setIcon(new ImageIcon(getClass().getResource("/iconos/door_in.png")));
			jBSalir.addActionListener(this);
		}
		return jBSalir;
	}
	/**
	 * //TODO:
	 * Controla la pulsación de los botones
	 */
	public void actionPerformed(ActionEvent e) 
	{
		if (e.getActionCommand().equals("salir"))
			System.exit(0);
		else if(e.getActionCommand().equals("comandas"))
		{
			this.dispose();	//esconde la ventana y se deshace de ella
			new Pedidos(r).setVisible(true);
		}
		else if(e.getActionCommand().equals("platos"))
		{
			this.dispose();	//esconde la ventana y se deshace de ella
			new SevirPlatos(r).setVisible(true);
		}
	}
}
